package com.wjk.exceptionHandler;

import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.omg.CORBA.UserException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author: RobertWei
 * time: 2021/8/12    11:38
 * @TODO:
 */

@ControllerAdvice
public class AllExceptionHandler {

    @ExceptionHandler(UserException.class)
    public ModelAndView userExceptionHandler(UserException ue){

        ModelAndView modelAndView = new ModelAndView();

        modelAndView.setViewName("error");
        modelAndView.addObject("msg",ue.getMessage());

        return modelAndView;

    }

    @ExceptionHandler(UnauthorizedException.class)
    public ModelAndView userExceptionHandler(UnauthorizedException ue){

        ModelAndView modelAndView = new ModelAndView();

        modelAndView.setViewName("error");
        modelAndView.addObject("msg","未授权");

        return modelAndView;

    }

    @ExceptionHandler(UnauthenticatedException.class)
    public ModelAndView userExceptionHandler(UnauthenticatedException ue){

        ModelAndView modelAndView = new ModelAndView();

        modelAndView.setViewName("error");
        modelAndView.addObject("msg","未认证");

        return modelAndView;

    }

}
